/**
 * 文件相关类型定义
 */
import { BaseFileInfo, BaseExportConfig, BaseImportConfig } from './base.types'

/**
 * 文件信息扩展
 */
export interface FileInfo extends BaseFileInfo {
  isFile?: boolean
  isDirectory?: boolean
  isSymlink?: boolean
  permissions?: FilePermissions
  owner?: string
  group?: string
  extension?: string
  mimeType?: string
  encoding?: string
  checksum?: string
  error?: string
}

/**
 * 文件权限
 */
export interface FilePermissions {
  readable: boolean
  writable: boolean
  executable: boolean
  mode: number
  octal: string
}

/**
 * 目录内容
 */
export interface DirectoryContent {
  path: string
  files: FileInfo[]
  directories: FileInfo[]
  total: number
  size: number
  lastModified: string
}

/**
 * 文件操作选项
 */
export interface FileOperationOptions {
  overwrite?: boolean
  createDirectories?: boolean
  preserveTimestamps?: boolean
  followSymlinks?: boolean
  encoding?: BufferEncoding
  mode?: number
}

/**
 * 文件搜索选项
 */
export interface FileSearchOptions {
  pattern: string
  directory: string
  recursive?: boolean
  caseSensitive?: boolean
  includeHidden?: boolean
  fileTypes?: string[]
  sizeRange?: {
    min?: number
    max?: number
  }
  dateRange?: {
    start?: string
    end?: string
  }
  maxResults?: number
}

/**
 * 文件搜索结果
 */
export interface FileSearchResult {
  files: FileInfo[]
  total: number
  searchTime: number
  query: FileSearchOptions
}

/**
 * 文件监听选项
 */
export interface FileWatchOptions {
  recursive?: boolean
  persistent?: boolean
  ignoreInitial?: boolean
  ignored?: string | RegExp | Array<string | RegExp>
  followSymlinks?: boolean
  depth?: number
}

/**
 * 文件变更事件
 */
export interface FileChangeEvent {
  type: 'add' | 'change' | 'unlink' | 'addDir' | 'unlinkDir'
  path: string
  stats?: FileInfo
  timestamp: string
}

/**
 * 资源数据
 */
export interface AssetData {
  id: string
  name: string
  type: AssetType
  category: string
  path: string
  url?: string
  size: number
  duration?: number
  resolution?: {
    width: number
    height: number
  }
  thumbnail?: string
  preview?: string
  metadata: AssetMetadata
  tags: string[]
  createdAt: string
  updatedAt: string
  projectId?: string
  isPublic: boolean
  downloadCount: number
  rating: number
  license: AssetLicense
}

/**
 * 资源类型
 */
export type AssetType = 
  | 'image' 
  | 'audio' 
  | 'video' 
  | 'animation' 
  | 'model' 
  | 'texture' 
  | 'font' 
  | 'document' 
  | 'archive' 
  | 'other'

/**
 * 资源元数据
 */
export interface AssetMetadata {
  format: string
  codec?: string
  bitrate?: number
  sampleRate?: number
  channels?: number
  colorSpace?: string
  hasAlpha?: boolean
  animated?: boolean
  frameCount?: number
  fps?: number
  author?: string
  copyright?: string
  description?: string
  keywords?: string[]
  camera?: {
    make?: string
    model?: string
    settings?: Record<string, any>
  }
  location?: {
    latitude?: number
    longitude?: number
    altitude?: number
  }
  software?: string
  customProperties?: Record<string, any>
}

/**
 * 资源许可证
 */
export interface AssetLicense {
  type: 'free' | 'premium' | 'royalty-free' | 'creative-commons' | 'custom'
  name: string
  url?: string
  attribution?: string
  commercial: boolean
  modification: boolean
  distribution: boolean
  price?: number
  currency?: string
}

/**
 * 资源导入选项
 */
export interface AssetImportOptions extends BaseImportConfig {
  generateThumbnail?: boolean
  extractMetadata?: boolean
  optimizeSize?: boolean
  convertFormat?: string
  quality?: number
  maxResolution?: {
    width: number
    height: number
  }
  tags?: string[]
  category?: string
  isPublic?: boolean
}

/**
 * 资源导入请求
 */
export interface AssetImportRequest {
  files: string[]
  projectId?: string
  options?: AssetImportOptions
}

/**
 * 资源导出选项
 */
export interface AssetExportOptions extends BaseExportConfig {
  includeMetadata?: boolean
  watermark?: {
    enabled: boolean
    text?: string
    opacity?: number
  }
  resize?: {
    width?: number
    height?: number
    maintainAspectRatio?: boolean
  }
}

/**
 * 资源查询参数
 */
export interface AssetQueryParams {
  type?: AssetType[]
  category?: string[]
  tags?: string[]
  search?: string
  projectId?: string
  isPublic?: boolean
  license?: string[]
  sizeRange?: {
    min?: number
    max?: number
  }
  dateRange?: {
    start?: string
    end?: string
  }
  sortBy?: 'name' | 'size' | 'created' | 'updated' | 'downloads' | 'rating'
  sortOrder?: 'asc' | 'desc'
  page?: number
  pageSize?: number
}

/**
 * 文件上传进度
 */
export interface FileUploadProgress {
  fileId: string
  fileName: string
  loaded: number
  total: number
  percent: number
  speed: number
  eta: number
  status: 'pending' | 'uploading' | 'completed' | 'error' | 'cancelled'
  error?: string
}

/**
 * 文件下载进度
 */
export interface FileDownloadProgress {
  fileId: string
  fileName: string
  loaded: number
  total: number
  percent: number
  speed: number
  eta: number
  status: 'pending' | 'downloading' | 'completed' | 'error' | 'cancelled'
  error?: string
}

/**
 * 文件压缩选项
 */
export interface FileCompressionOptions {
  format: 'zip' | 'tar' | 'gzip' | '7z'
  level?: number
  password?: string
  includeHidden?: boolean
  followSymlinks?: boolean
  excludePatterns?: string[]
}

/**
 * 文件解压选项
 */
export interface FileExtractionOptions {
  destination: string
  overwrite?: boolean
  password?: string
  preservePaths?: boolean
  selectedFiles?: string[]
}

/**
 * 文件同步选项
 */
export interface FileSyncOptions {
  source: string
  destination: string
  bidirectional?: boolean
  deleteExtraneous?: boolean
  preserveTimestamps?: boolean
  excludePatterns?: string[]
  dryRun?: boolean
}

/**
 * 文件同步结果
 */
export interface FileSyncResult {
  copied: number
  updated: number
  deleted: number
  skipped: number
  errors: Array<{
    file: string
    error: string
  }>
  duration: number
}

/**
 * 文件备份配置
 */
export interface FileBackupConfig {
  enabled: boolean
  schedule: 'manual' | 'hourly' | 'daily' | 'weekly' | 'monthly'
  retention: number
  compression: boolean
  encryption: boolean
  destination: string
  includePatterns: string[]
  excludePatterns: string[]
}

/**
 * 文件版本信息
 */
export interface FileVersion {
  id: string
  fileId: string
  version: number
  size: number
  checksum: string
  createdAt: string
  createdBy: string
  comment?: string
  changes?: Array<{
    type: 'added' | 'modified' | 'deleted'
    line?: number
    content?: string
  }>
}

/**
 * 文件共享信息
 */
export interface FileShare {
  id: string
  fileId: string
  shareType: 'public' | 'private' | 'password' | 'expiring'
  shareUrl: string
  password?: string
  expiresAt?: string
  downloadLimit?: number
  downloadCount: number
  permissions: {
    canView: boolean
    canDownload: boolean
    canComment: boolean
  }
  createdAt: string
  createdBy: string
}

/**
 * 文件统计信息
 */
export interface FileStats {
  totalFiles: number
  totalSize: number
  filesByType: Record<AssetType, number>
  sizeByType: Record<AssetType, number>
  recentFiles: FileInfo[]
  largestFiles: FileInfo[]
  duplicateFiles: Array<{
    checksum: string
    files: FileInfo[]
    totalSize: number
  }>
  storageUsage: {
    used: number
    available: number
    total: number
    percent: number
  }
}
